package com.sofoscorp.android.gestcobranzamobile;

import java.util.ArrayList;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.util.Log;

public class BNKP_BO {
	private String C_TABNAME = "BNKP";
	private ConexionDB go_conexDB;
	private Cursor gc_BNKP;
	private SQLiteDatabase go_db;
	
	private BNKP_Str gs_BNKP = null;
	private BNKP_Str[] gt_BNKP = null;
	String[] gt_campos = new String[]{"BUKRS", "HBKID", "TEXTBK", "BANKN","TEXTO"};
	
	public BNKP_BO(){
		go_conexDB = new ConexionDB();
	}
	
	public BNKP_Str[] get_AllBNKP(){
		ArrayList<BNKP_Str> lt_List = new ArrayList<BNKP_Str>();
		gc_BNKP = null;
		
		//Pasar el Path de DB
		go_conexDB.serialization(go_conexDB.C_PATH_FROMSAP);
		
		//Verificar si existe conexion con la DB
		if (go_conexDB.checkConexDB()) {
			
			//Obtener la DB
			go_db = go_conexDB.getGo_DB();
			try {
				//Ejecutar Select a la DB
				gc_BNKP = go_db.query(C_TABNAME, gt_campos, null, null, null, null, null, null);
				if (gc_BNKP.moveToFirst()) {
					//Recorrer el cursor
					do {
						lt_List.add(new BNKP_Str(	gc_BNKP.getString(0), 
													gc_BNKP.getString(1), 
													gc_BNKP.getString(2), 
													gc_BNKP.getString(3),
													gc_BNKP.getString(4)));
						Log.w("W", "Banco "+ gc_BNKP.getString(1));
					} while (gc_BNKP.moveToNext());
					//Pasar los datos del Lista al Arreglo de objetos
					gt_BNKP = lt_List.toArray(new BNKP_Str[0]);
				}else{
					gt_BNKP = null;
					lt_List = null;
				}
			} catch (Exception e) {
				// TODO: handle exception
			}
		}else{
			gt_BNKP = null;
			lt_List = null;
		}
		
		go_db.close();
		gc_BNKP.close();
		return gt_BNKP;
	}
}
